<?php
function AddOutloginForm ($target){
	global $service, $hostURL, $blogURL,$serviceURL,$defaultURL;
	list($loginhtml, $logouthtml, $logincss) = OutloginSetting();

	$loginhtml = str_replace("<!--cookieloginid-->",htmlspecialchars(empty($_POST['loginid']) ? (empty($_COOKIE['TSSESSION_LOGINID']) ? '' : $_COOKIE['TSSESSION_LOGINID']) : $_POST['loginid']),$loginhtml);
//echo htmlspecialchars(empty($_POST['loginid']) ? (empty($_COOKIE['TSSESSION_LOGINID']) ? '' : $_COOKIE['TSSESSION_LOGINID']) : $_POST['loginid']);

	if (doesHaveOwnership()) {
		ob_start();
?>
	<!-- Textcube OutLogout Form Start -->
	<form method="post" action="<? echo $defaultURL."/logout"?>">
		<input type="hidden" name="requestURI" value="<?=$hostURL.$_SERVER['REQUEST_URI']?>" />
<?=$logouthtml?>
	</form>
	<!-- Textcube OutLogout Form Start -->
<?
	$temp = ob_get_contents();
	ob_end_clean();
	}
	else {
	ob_start();
?>
	<!-- Textcube OutLogin Form Start -->
	<form method="post" action="<? echo $defaultURL."/login"?>">
		<input type="hidden" name="requestURI" value="<?=$hostURL.$_SERVER['REQUEST_URI']?>" />
<?=$loginhtml?>
	</form>
	<!-- Textcube OutLogin Form End -->
<?
	$temp = ob_get_contents();
	ob_end_clean();
	}

	return $logincss.$temp;

}

function OutloginSetting()
{
	global $configVal;
	requireComponent('Textcube.Function.misc');
	$settingdata = misc::fetchConfigVal( $configVal);

ob_start();
?>
		<div class="outlogin">
			<dl>
				<dt><label for="loginid">이메일</label></dt>
				<dd><input type="text" class="input-text" id="loginid" name="loginid" value="<!--cookieloginid-->" maxlength="64" size="15" /></dd>
		    	<dt><label for="password">비밀번호</label></dt>
				<dd><input type="password" class="input-text" id="password" name="password" onkeydown="if (event.keyCode == 13) document.forms[0].submit()" maxlength="64" size="15" /></dd>
			</dl>
				<div class="email-save"><input type="checkbox" id="save" class="checkbox" name="save"checked="checked" /> <label for="save">이메일 저장</label></div>
				<div class="button-box"><input type="submit" class="login-button input-button" value="로그인" /></div>
		</div>
<?
$outloginhtml = ob_get_contents();
ob_end_clean();

ob_start();
?>
		<div class="outlogout">
			<dl>
				<dt>관리자 로그인 상태입니다.</dt>
				<dd><input type="submit" class="outlogout button" value="로그아웃" /></dd>
			</dl>
		</div>
<?
$outlogouthtml = ob_get_contents();
ob_end_clean();

ob_start();
?>
.outlogin {
	text-align:right;
	background-color:#eee;
	margin:0 5px;
	padding:0 5px;
	border:1px solid #aaa;
}
.outlogin dt
{
	float:left;
}

.outlogin .email-save
{
	float:left;
}

.outlogout {
	padding:1px 10px;
	margin:3px 0;
	background-color:#eee;
	text-align:center;
}
.outlogout dd {
	text-align:right;
	margin-top:2px;
	margin-right:8px;
}
<?
$outlogincss = ob_get_contents();
ob_end_clean();


	if( !is_null( $settingdata ) ){
		$outloginhtml = $settingdata['loginhtmlset'];
		$outlogouthtml = $settingdata['logouthtmlset'];
		$outlogincss = $settingdata['cssset'];
	}

	$outlogincss = "<style>\n". $outlogincss . "\n</style>\n";
	return array ($outloginhtml,$outlogouthtml,$outlogincss);
}
?>
